﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelperPrototype._DB
{
    class NhomNguoiDungDB
    {
        public static IQueryable selectAll()
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = from u in db.NhomNguoiDungs
                        where u.deleted ==false
                        select u;
            return query;
        }
        public static bool insert(_DB.NhomNguoiDung u)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            db.NhomNguoiDungs.InsertOnSubmit(u);
            db.SubmitChanges();
            return true;
        }
        public static NhomNguoiDung update(NhomNguoiDung newGroup)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = (from u in db.NhomNguoiDungs
                         where u.NhomNguoiDung_ID == newGroup.NhomNguoiDung_ID
                         select u);
            if (query.Count() > 0)
            {
                NhomNguoiDung ug = query.First();
                ug.TenNhom = newGroup.TenNhom;
                ug.GhiChu = newGroup.GhiChu;
                ug.TrangThai = newGroup.TrangThai;
                ug.deleted = newGroup.deleted;
                db.SubmitChanges();
                //  return query.First();
            }
            return null;
            //return query;
        }
        public static void delete(int id)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = from u in db.NhomNguoiDungs
                        where u.NhomNguoiDung_ID == id
                        select u;
            if (query.Count() > 0)
            {
                NhomNguoiDung ug = query.First();
                ug.deleted = true;
                db.SubmitChanges();
            }
            return ;
            //return query;
        }
    }
}
